//
//  FailureViewController.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/8/20.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import UIKit

/// 失败页面
class FailureViewController: BaseUIViewController {
    
    let psrCheckId: String
    let barCode: String
    let errorMessage: String
    let errorCode: String
    
    init(psrCheckId: String, barCode: String, errorMessage: String, errorCode: String) {
        self.psrCheckId = psrCheckId
        self.barCode = barCode
        self.errorMessage = errorMessage
        self.errorCode = errorCode
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let imageView = UIImageView().config
            .imageName("failure_image_cn".localized)
            .contentMode(.scaleAspectFit)
            .addTo(view)
            .view
        
        imageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(40)
            make.left.equalTo(50)
            make.height.equalTo(imageView.snp.width)
        }
        
        let errorLabel = UILabel().config
            .text("(" + errorCode + ")")
            .textColor(#colorLiteral(red: 0.6, green: 0.6, blue: 0.6, alpha: 1))
            .font(UIFont.systemFont(ofSize: 13, weight: .medium))
            .isHidden(errorCode.count == 0)
            .addTo(view)
            .makeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.bottom.equalTo(-UIApplication.shared.bottomSafeDistance - 20)
            }.view
        
        let tipLabel = UILabel().config
            .text(errorMessage)
            .textColor(#colorLiteral(red: 0.6, green: 0.6, blue: 0.6, alpha: 1))
            .font(UIFont.systemFont(ofSize: 13, weight: .medium))
            .numberOfLines(0)
            .textAlignment(.center)
            .addTo(view)
            .makeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.bottom.equalTo(errorLabel.snp.top).offset(-20)
                make.left.equalTo(40)
            }.view
        
        UIButton().config
            .backgroundImage(UIImage.imageWithColor(APPConfig.baseColor))
            .title("报假信息".localized)
            .cornerRadius(5)
            .clipsToBounds(true)
            .titleColor(.white)
            .addTarget(self, action: #selector(reportFake))
            .addTo(view)
            .makeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.left.equalTo(40)
                make.height.equalTo(50)
                make.bottom.equalTo(tipLabel.snp.top).offset(-15)
        }
    }
    
    @objc func reportFake() {
        let vc = ReportFackViewController(psrCheckId: psrCheckId, barCode: barCode)
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    override func navigationBarStyle() -> NavigationBarStyle {
        return .baseColor
    }
    
}
